On Error Resume Next
Computer = "."
Const ForAppending = 2

Dim buffer
set buffer = ""
buffer = buffer & "{"
Set WMIService = GetObject("winmgmts:\\" & Computer & "\root\cimv2")
Set Items = WMIService.ExecQuery("Select * from Win32_SerialPort",,48)
buffer = buffer &   """ports"""&":["
Dim  isFirst
isFirst = true
For Each SubItems in Items
if isFirst = false then
	buffer = buffer &   "," 
end if

buffer = buffer &   "{"
       
    buffer = buffer &   """device""" &": " & chr(34) & SubItems.DeviceID & chr(34) &","
 
    buffer = buffer &   """name"":"  & chr(34) & SubItems.Name & chr(34)
   
buffer = buffer &   "}"
IF isFirst = true 	THEN 
	isFirst = false	
END IF

Next
buffer = buffer &   "]"
buffer = buffer &   "}"



'Set FileSystem = CreateObject("Scripting.FileSystemObject")
'Set TextFile = FileSystem.OpenTextFile ("serial_ports.json", ForAppending, True)
'TextFile.Write buffer
'TextFile.Close

Set fso = CreateObject ("Scripting.FileSystemObject")
Set stdout = fso.GetStandardStream (1)
'stdout.WriteLine "This will go to standard output."
stdout.Write buffer

